#ifndef TC_HEAPMGR_HH
#define TC_HEAPMGR_HH

/** \file HeapMgr.hh 
 * Declarations for the class HeapMgr.
 *
 * (c) Copyright  Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: HeapMgr.hh 119 2006-06-21 04:57:25Z semihc $
 *
 *
 */


#include <cstddef>
#include <new>
#include "Frame.hh"
#include "Heap.hh"


namespace TC {

  //! Constant to control redefinitions of global new-delete
  const bool Redefine_Global_New = 
#ifdef TC_REDEFINE_GLOBAL_NEW
              true;
#else
              false; 
#endif


  class HeapMgr
  {
  public:
    // TYPES
      
    // CREATORS
      
    // ACCESSORS
      
    // MODIFIERS
      
    // STATIC FUNCTIONS
    //! Set currently active heap manager.
    //! Returns previous manager.
    static Heap* SetCurrentHeap(Heap* h);

    //! Get currently active heap manager.
    static Heap* GetCurrentHeap()
    { return CurrentHeap(); }

    //! Get the default heap manager.
    static Heap* GetDefaultHeap()
    { return DefaultHeap(); }

    //! Find which heap owns the ptr.
    static Heap* WhichHeap(void* ptr);


  private:
    // NOT IMPLEMENTED
    
    // MEMBERS

    // STATIC MEMBERS
    //! Current heap manager is accessed by this function.
    static Heap*& CurrentHeap();

    //! The default heap manager is accessed by this function.
    //! At the start-up default heap becomes current one.
    static Heap* DefaultHeap();


  }; // end class

} // end namespace



# ifdef TC_REDEFINE_GLOBAL_NEW

 /**
  * Global redefinitions for various operator new() and delete()s.
  * Note that it is important NOT to override the "placement" new
  * [ie., operator new(size_t, void*) ] and delete since they don't
  * involve memory management operations. Consequently, we should 
  * be using C++ implementation's version.
  */

 void* operator new(size_t size) throw(std::bad_alloc);
 void* operator new[](size_t size) throw(std::bad_alloc);

 void operator delete(void *ptr) throw();
 void operator delete[](void *ptr) throw();

 void* operator new(size_t size, const std::nothrow_t&) throw();
 void* operator new[](size_t size, const std::nothrow_t&) throw();

 /* Followings probably are not required.
 void operator delete(void *ptr, const std::nothrow_t&) throw();
 void operator delete[](void *ptr, const std::nothrow_t&) throw();
 */

# endif /* TC_REDEFINE_GLOBAL_NEW */



#endif /* TC_HEAPMGR_HH */
